<script setup lang="ts">
const getPhoneNumber = (): void => {
  console.log("获取手机号");
  // eslint-disable-next-line no-undef
  my.getPhoneNumber({
    success: (res) => {
      const encryptedData = res.response;
      console.log("加密手机号数据:", encryptedData);
      // 发送给后端解密
    },
    fail: (err) => {
      console.error("获取手机号失败:", err);
    },
  });
};

const handleAuthError = (err: any) => {
  console.error("授权失败:", err);
};

function getAuthCode(): void {
  // eslint-disable-next-line no-undef
  my.getAuthCode({
    scopes: "auth_user",
    success: (res) => {
      const authCode = res.authCode;
      console.log(authCode);
    },
    fail: (err) => {
      console.log("my.getAuthCode 调用失败", err);
    },
  });
}
function startTradePay(): void {
  uni.requestPayment({
    provider: "alipay",
    orderInfo: "2025072122001453280506154657", // 后端返回的订单号
    success: function (res) {
      console.log("支付成功", res);
    },
    fail: function (err) {
      console.error("支付失败", err);
    },
  });
}
</script>

<template>
  <view class="page">
    <button
      data-v-59dbf647=""
      data-v-f44e1744=""
      id=""
      class="sar-button sar-button_medium sar-button_default sar-button_default-primary sar-button_block"
      lang="en"
      style="background-color: #1ec8c8; color: #fff"
      show-message-card="false"
      open-type="getAuthorize"
      scope="phoneNumber"
      @getAuthorize="getPhoneNumber"
      @error="handleAuthError"
    >
      一键登录
    </button>
    <nut-button type="pale" @click="getAuthCode"> 获取授权码 </nut-button>
    <nut-button type="outline" @click="startTradePay"> 立即支付 </nut-button>
  </view>
</template>

<style scoped lang="scss" src="./index.scss"></style>
